#include <iostream>
#include <ctime>
#include "ThreadPool.hpp"
#include "Task.hpp"

pthread_spinlock_t slock; // 自旋锁

int main()
{
    std::cout << "process running..." << std::endl;
    sleep(3);

    ThreadPool<Task>::GetInstance()->Start();
    srand(time(nullptr) ^ getpid()); // 随机性更强

    while (true)
    {
        int x = rand() % 10 + 1;
        usleep(10);
        int y = rand() % 5;
        char op = opers[rand() % opers.size()];

        Task t(x, y, op);
        ThreadPool<Task>::GetInstance()->Push(t); // 交给线程池处理

        std::cout << "main thread make task: " << t.GetTask() << std::endl;
        sleep(1);
    }

    return 0;
}